package com.demo.helper;

import android.view.View;
import android.widget.ImageView;

import com.appbase.custom.constant.CommonConstants;
import com.module.commonui.R;
import com.tange.base.toolkit.PreferenceUtil;
import com.tg.appcommon.android.TGApplicationBase;

public class BatteryHelper {

    public static boolean showBattery(int userId, String uuid){
        boolean show = PreferenceUtil.contains(TGApplicationBase.getApplicationContext(), CommonConstants.PRE_SETTINGS_BATTERY_UUID + uuid + userId);
        if (!show){
            show = true;
        }else{
            show =  PreferenceUtil.getBoolean(TGApplicationBase.getApplicationContext(), CommonConstants.PRE_SETTINGS_BATTERY_UUID + uuid + userId);
        }
        return show;
    }

    public static void setBattery(ImageView imageView, int mode, int battery, boolean passiveDevice){
        if (mode == -1 && battery == -1){
            imageView.setVisibility(View.GONE);
            return;
        }

        if (mode == 1){
            if (battery < 20){
                imageView.setImageResource(passiveDevice? R.drawable.ic_tange_battery_passive_charge10 : R.drawable.ic_tange_battery_charge10);
            }else if (battery < 40){
                imageView.setImageResource(passiveDevice? R.drawable.ic_tange_battery_passive_charge30 : R.drawable.ic_tange_battery_charge30);
            }else if (battery < 60){
                imageView.setImageResource(passiveDevice? R.drawable.ic_tange_battery_passive_charge50 : R.drawable.ic_tange_battery_charge50);
            }else if (battery < 80){
                imageView.setImageResource(passiveDevice? R.drawable.ic_tange_battery_passive_charge90 : R.drawable.ic_tange_battery_charge90);
            }else{
                imageView.setImageResource(passiveDevice? R.drawable.ic_tange_battery_passive_charge100 : R.drawable.ic_tange_battery_charge100);
            }
        }else{
            if (battery < 20){
                imageView.setImageResource(passiveDevice? R.drawable.icon_camera_player_battery_svg10 : R.drawable.icon_camera_solar_player_battery_svg10);
            }else if (battery < 40){
                imageView.setImageResource(passiveDevice? R.drawable.icon_camera_player_battery_svg30 : R.drawable.icon_camera_player_solar_battery_svg30);
            }else if (battery < 60){
                imageView.setImageResource(passiveDevice? R.drawable.icon_camera_player_battery_svg50 : R.drawable.icon_camera_player_solar_battery_svg50);
            }else if (battery < 80){
                imageView.setImageResource(passiveDevice? R.drawable.icon_camera_player_battery_svg90 : R.drawable.icon_camera_player_solar_battery_svg90);
            }else{
                imageView.setImageResource(passiveDevice? R.drawable.icon_camera_player_battery_svg100 : R.drawable.icon_camera_player_solar_battery_svg100);
            }
        }
    }
}
